package com.loong.system.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.system.common.backend.param.SystemConfigTypeParam;
import com.loong.system.handler.SystemConfigTypeHandler;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 配置类型控制器
 */
@RestController
@RequestMapping("/manage/system/configType")
public class SystemConfigTypeController extends BaseBackendController {
    @Resource
    private SystemConfigTypeHandler systemConfigTypeHandler;

    /**
     * 保存配置类型
     * @param param
     * @return
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class})SystemConfigTypeParam param){
        param.setId(null);
        return handlerExecutor.execute(()->systemConfigTypeHandler.save(param));
    }


    /**
     * 更新配置类型
     * @param param
     * @return
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) SystemConfigTypeParam param){
        return  handlerExecutor.execute(()->systemConfigTypeHandler.update(param));
    }

    /**
     * 查询所有的配置类型
     * @return
     */
    @PostMapping("queryAll")
    public Result queryAll(){
        return handlerExecutor.execute(()->systemConfigTypeHandler.queryConfigTypeAll());
    }

    /**
     * 根据id删除配置类型
     * @param id
     */
    @PostMapping("delete")
    public Result deleteById(@RequestParam("id")  Long id){

        return handlerExecutor.execute(()->systemConfigTypeHandler.deleteConfigTypeById(id));
    }






}
